package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/4/29 10:55
 * @since v1.0
 */
@Getter
public enum PaymentLinkTypeEnum {
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(),"enum.paymentLinkType.attr.contract","contract"),
    REFUND(XbbRefTypeEnum.REFUND.getCode(),"enum.paymentLinkType.attr.refund","refund"),
    ;
    private Integer code;
    private String attr;
    private String alias;

    PaymentLinkTypeEnum(Integer code, String attr, String alias) {
        this.code = code;
        this.attr = attr;
        this.alias = alias;
    }

    public static PaymentLinkTypeEnum getByCode(Integer linkBusinessType) {
        for (PaymentLinkTypeEnum cacheCode : values()) {
            if (cacheCode.getCode().equals(linkBusinessType)) {
                return cacheCode;
            }
        }
        return CONTRACT;
    }

    public String getAttr() {
        return I18nMessageUtil.getMessage(attr);
    }
}
